
var _callback;

$(function(){
	
	initDesktop();
	$("ul.taskbar_start_menu li").mouseover(function(){
		$(this).addClass("menu_mouseover_background");
	}).mouseout(function(){
		$(this).removeClass("menu_mouseover_background");
	});
	
	d=300;
	$('#navigation a').each(function(){
                    $(this).stop().animate({
                        'marginTop':'-80px'
                    },d+=150);
                });

                $('#navigation > li').hover(
                function () {
                    $('a',$(this)).stop().animate({
                        'marginTop':'-2px'
                    },200);
                },
                function () {
                    $('a',$(this)).stop().animate({
                        'marginTop':'-80px'
                    },200);
                }
            );
                
                $("#home,#about").click(function(){
		boxyFacade("help_App13");		
	});
                
    //为管理员添加公告应用
//    $.get(getRootPath() + "/usermgnt/checkIsAdmin.do",function(isAdmin) {
//    	if(isAdmin == "true") {
//    		$('.appListContainer').icon({title:'公告管理',declare:'发布应用公告',id:'noticeManager',imgUrl:'framework/css/images/notice.png',left:'90px',top:'120px',appid:'NoticeManager_App11'});
//    	}
//    });
                
      //显示系统公告
      $.get(getRootPath() + "/noticemgnt/queryNewNotice.do",function(noticeText) {
    	  	if(noticeText != "") {
    	  		$("#noticeContent").show().html(noticeText);
    	  	}
      });
                
});

//初始化桌面
function initDesktop(){
	$("body").panel();
	$("#desktop").toolbar();
	loadIcons();
	$.get(getRootPath() +"/usermgnt/getUserInfo.do",function(response){
		$("body").menu({
		left:'10px',
		top:'30px',
		menuOpt:[
			{
				'id':'personalSettings',
				'refclass':'taskbar_start_menu_lock',
				'title':'个人设置'
			},
			{
				'id':'taskbar_helpButton',
				'refclass':'taskbar_start_menu_help',
				'title':'帮助'
			},
			{
				'id':'taskbar_logout',
				'refclass':'taskbar_start_menu_logout',
				'title':'注销'
			}
		],
		selfNickName:response
	});
		$("#personalSettings").click(function(){
		$("#startmenu").hide();
		boxyFacade("personalSettings_App7");		
	});
		
		$("#taskbar_helpButton").click(function(){
		$("#startmenu").hide();
		boxyFacade("help_App13");		
	});
	});
	
	
	
	
}

/**
 * 启动时加载桌面图标
 * @return
 */
function loadIcons(){	
	$('.appListContainer').icon({title:'流量统计',declare:'效果统计',id:'StatReport',imgUrl:'framework/desktopMgr/desktopIcon/images/SystemEqualizer.png',left:'0px',top:'360px',appid:'StatReport_App2'});
	$('.appListContainer').icon({title:'微博营销',declare:'我的营销中心',id:'marketingManager',imgUrl:'framework/desktopMgr/desktopIcon/images/GlobeActive.png',left:'0px',top:'280px',appid:'marketingManager_App6'});
	$('.appListContainer').icon({title:'粉丝管理',declare:'管理所有微博帐号的好友及粉丝',id:'contactPerson',imgUrl:'framework/desktopMgr/desktopIcon/images/contactpeople.png',left:'0px',top:'40px',appid:'contactPerson_App8'});
	$('.appListContainer').icon({title:'微博发送',declare:'即时微博,定时微博',id:'messageService',imgUrl:'framework/desktopMgr/desktopIcon/images/messageicon.png',left:'0px',top:'120px',appid:'messageService_App9'});
	$('.appListContainer').icon({title:'微博管理',declare:'个性化,多视图微博展现',id:'streamManager',imgUrl:'framework/desktopMgr/desktopIcon/images/netvibes_32.png',left:'0px',top:'200px',appid:'streamManager_App12'});
	$('.appListContainer').icon({title:'使用帮助',declare:'帮助您尽快的了解如何使用本系统',id:'help',imgUrl:'framework/desktopMgr/desktopIcon/images/ButtonWhiteHelp.png',left:'90px',top:'40px',appid:'help_App13'});
	$('.appListContainer').icon({title:'续费升级',declare:'升级,续费...',id:'buyUpdate',imgUrl:'framework/desktopMgr/desktopIcon/images/bonus_05.png',left:'90px',top:'120px',appid:'buyUpdate_App3'});
	$('.appListContainer').icon({title:'建议反馈',declare:'对招财猫的建议',id:'advise',imgUrl:'framework/desktopMgr/desktopIcon/images/advise.png',left:'90px',top:'200px',appid:'advise_App15'});
	
}

function showDesktop(){
	for(key in qBox.dialogs){
		dialog = qBox.dialogs[key];
		dialog._setupControls(dialog);
	}
}

function help() {
	
	boxyFacade("help_App13");	
}

function getRootPath(){
 var strFullPath=window.document.location.href;
 var strPath=window.document.location.pathname;
 var pos=strFullPath.indexOf(strPath);
 var prePath=strFullPath.substring(0,pos);
 var postPath=strPath.substring(0,strPath.substr(1).indexOf('/')+1);
 return(prePath+postPath);
}


//配置微博帐号
function weiboSetlink(options,callback) {
		_callback = callback;
		window.open(options.url,options.title,"height=400,width=800,scrollbars=yes,resizable=yes,top=100,left=300");
}

function closeOauthPage(userId,frameId){
	_callback(userId);
}
